<?php
include("../../config.php");
include(FILE_ROOT."/common/db.php");
include(FILE_ROOT."/common/WorkOrder.php");
include(FILE_ROOT."/common/user_client.php");
include(FILE_ROOT."/common/common_function.php");	
/*if(!checkIsLogin()){
    echo '{"status":-2,"message":"没有权限！","data":""}';
    return;
}*/

function gettoken()
{
	if(!empty($_POST['token'])||!empty($_GET['token']))
	{
	  $token=empty($_POST['token'])?$_GET["token"]:$_POST["token"];		
	}
	else
	{
		$token=$_COOKIE["CCUSER"];
	}
	return $token;
}

function getdata($key){
	
	if(isset($_POST[$key]))
	{
		return $_POST[$key];
	}
	else
	{
		if(isset($_GET[$key]))
		{
			return $_GET[$key];
		}
		else
		{
			return "";
		}
	}
}
$workorder=new WorkOrder();
$op = empty($_POST["action"])?$_GET["action"]:$_POST["action"];
$db=new DB();
switch($op){ 
		case 'create':
		$arr=array();
		//获取创建者的Id，需要传token的(安卓)
		//$token=empty($_POST['token'])?$_GET["token"]:$_POST["token"];
		$token=gettoken();
		$uid1=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$arr['CreatePersonId']=$uid1['uid'];
		$userType=$uid1['Type'];
		//获取客户的id
		$cname=empty($_POST['cname'])?$_GET["cname"]:$_POST["cname"];
		$uid2=$db->getOne("SELECT * from chu_user where uname='".$cname."'");
		//得到线路id
		$LineId=empty($_POST['LineId'])?$_GET["LineId"]:$_POST["LineId"];
		$arr['LineId']=$LineId;
		if($userType=="客户")
		{
			if($uid1['uname']!=$cname)
			{
				$workorder->error("只能跟自己创建工单！请输入自己的用户名！")->end();
				break;
			}
		}else{
			if(empty($uid2['uname']))
			{
				$workorder->error("该客户不存在，先通知改客户注册！")->end();
				break;
			}
		}
		$arr['ClientId']=$uid2['uid'];
		$arr['Type']=empty($_POST['Type'])?(empty($_GET["Type"])?222:$_GET["Type"]):$_POST["Type"];
		$arr['OutletId']=empty($_POST['OutletId'])?(empty($_GET["OutletId"])?1001:$_GET["OutletId"]):$_POST["OutletId"];
		$arr['Context']=empty($_POST['Context'])?$_GET["Context"]:$_POST["Context"];
		$arr['Status']='未调度';
		$arr['CreateTime']=Time();
		$arr['DateTime']=empty($_POST['DateTime'])?strtotime($_GET['DateTime']):strtotime($_POST['DateTime']);//时间转换时间戳
		$workorder->create($arr,$userType)->end();

		//还需要做推送
		break;
	case 'create2':
		$arr=array();
		//获取创建者的Id,不用传token的

		$token=$_COOKIE["CCUSER"];
		$uid1=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$userType=$uid1['Type'];
		$arr['CreatePersonId']=$uid1['uid'];
		//p($arr['CreatePersonId']);die;
		//获取客户的id
		$cname=empty($_POST['cname'])?$_GET["cname"]:$_POST["cname"];
		$uid2=$db->getOne("SELECT uid,uname from chu_user where uname='".$cname."'");

		//得到线路id
		$LineId=empty($_POST['LineId'])?$_GET["LineId"]:$_POST["LineId"];
		$arr['LineId']=$LineId;
		
		if($userType=="客户")
		{
			if($uid1['uname']!=$cname)
			{
				$workorder->error("只能跟自己创建工单！请输入自己的用户名！")->end();
				break;
			}
		}else{
			if(empty($uid2['uname']))
			{
				$workorder->error("该客户不存在，先通知改客户注册！")->end();
				break;
			}
		}

		$arr['ClientId']=$uid2['uid'];
		$arr['Type']=empty($_POST['Type'])?(empty($_GET["Type"])?222:$_GET["Type"]):$_POST["Type"];
		$arr['OutletId']=empty($_POST['OutletId'])?(empty($_GET["OutletId"])?1001:$_GET["OutletId"]):$_POST["OutletId"];
		$arr['Context']=empty($_POST['Context'])?$_GET["Context"]:$_POST["Context"];
		$arr['Status']="未调度";
		$arr['CreateTime']=Time();
		$arr['DateTime']=empty($_POST['DateTime'])?strtotime($_GET['DateTime']):strtotime($_POST['DateTime']);//时间转换时间戳
		//$arr['redirectUrl']="/Line/listworkorder?lineId=".$LineId."&action=orderListByLineId";
		$workorder->create($arr,$userType)->end();
		//还需要做推送
		break;
	case 'update':
		//需要传token的(安卓)
		$arr=array();
		$token=empty($_POST['token'])?$_GET["token"]:$_POST["token"];
		$uid=$db->getOne("SELECT uid from chu_user where token='".$token."'");
		$arr['HandlerId']=$uid['uid'];
		$arr['Id']=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$arr['Status']=empty($_POST['Status'])?$_GET["Status"]:$_POST["Status"];
		$arr['Handle']=empty($_POST['Handle'])?$_GET["Handle"]:$_POST["Handle"];
		$workorder->update($arr)->end();
		//还需要做推送
		break;
	case 'update2':
		//不需要传token的(前台)
		$arr=array();
		$token=$_COOKIE["CCUSER"];
		$uid=$db->getOne("SELECT uid from chu_user where token='".$token."'");
		$arr['HandlerId']=$uid['uid'];
		$arr['Id']=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$arr['Status']=empty($_POST['Status'])?$_GET["Status"]:$_POST["Status"];
		$arr['Handle']=empty($_POST['Handle'])?$_GET["Handle"]:$_POST["Handle"];

		$arr['Explain']=empty($_POST['Explain'])?(empty($_GET["Explain"])?"":$_GET["Explain"]):$_POST["Explain"];
		
		$workorder->update($arr)->end();
		//还需要做推送
		break;
	case 'orderList':
		//得到自己相关的工单列表，不需要传token(前台)
		$token=gettoken();
		//$serachKey=$_POST['searchKey'];

		 //$serachKey=empty($_POST['searchKey'])?(empty($_GET["searchKey"])?"-1":$_GET["searchKey"]):$_POST["searchKey"];
		$search=array();
		$search['searchKey']=getdata('searchKey');
		$search['searchDateStart']=getdata('searchDateStart');
		$search['searchDateEnd']=getdata('searchDateEnd');
		$search['nodispatch']=getdata('nodispatch')==""?1:getdata('nodispatch');
		$search['nohandle']=getdata('nohandle')==""?1:getdata('nohandle');
		$search['handled']=getdata('handled')==""?1:getdata('handled');
		//获取分页参数
		//$current_page=empty($_GET['current_page'])?"1":$_GET["current_page"];
	    $current_page=empty($_POST['current_page'])?(empty($_GET["current_page"])?1:$_GET["current_page"]):$_POST["current_page"];
		$item_everypage=empty($_POST['item_everypage'])?(empty($_GET["item_everypage"])?10:$_GET["item_everypage"]):$_POST["item_everypage"];			
		//$item_everypage=empty($_GET['item_everypage'])?"10":$_GET["item_everypage"];

		$uid=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$userType=$uid['Type'];
		$uid=$uid['uid'];
		$data=$workorder->workOrderList($search,$uid,$userType,$current_page,$item_everypage);
		//p($uid);die;
		$workorder->data($data)->end();
		break;
	case 'getClientList':
		$token=gettoken();
		$search=array();
		$search['searchKey']=getdata('searchKey');
		
		//获取分页参数
		//$current_page=empty($_GET['current_page'])?"1":$_GET["current_page"];
	    $current_page=empty($_POST['current_page'])?(empty($_GET["current_page"])?1:$_GET["current_page"]):$_POST["current_page"];
		$item_everypage=empty($_POST['item_everypage'])?(empty($_GET["item_everypage"])?10:$_GET["item_everypage"]):$_POST["item_everypage"];			
		//$item_everypage=empty($_GET['item_everypage'])?"10":$_GET["item_everypage"];

		$uid=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$userType=$uid['Type'];
		
		$region_id=$uid['region_id'];
		$data=$workorder->clientList($search,$userType,$region_id,$current_page,$item_everypage);
		//p($uid);die;
		$workorder->data($data)->end();
		break;
		
	case 'orderListPhone':
		//得到自己相关的工单列表，需要传token(安卓)
		$token=empty($_POST['token'])?$_GET["token"]:$_POST["token"];
		$uid=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$userType=$uid['Type'];
		$uid=$uid['uid'];
		$data=$workorder->workOrderList($uid,$userType);
		//p($uid);die;
		$workorder->data($data)->end();
		break;
	case 'Detail':
	//某个工单的详细信息(前台，安卓)
		$wid=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$data=$workorder->workOrderDetailById($wid);
		//p($data);die;
		$workorder->data($data)->end();
		break;
	case 'routeList':
	//某个工单的路由信息(前台，安卓)
		$wid=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$data=$workorder->routeLogById($wid);
		//p($data);die;
		$workorder->data($data)->end();
		break;

	case 'initWorkOrder':
	//初始化工单（前台）
		$token=gettoken();
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$userType=$user['Type'];
		$uid=$user['uid'];
		$region_id=$user['region_id'];
		$data=$workorder->initWorkOrder($userType,$region_id);
		if($userType=="客户"){
			$data['cname']=$user['uname'];
			$data['LineId']=empty($_POST['LineId'])?$_GET["LineId"]:$_POST["LineId"];
			$data['LineName']=empty($_POST['LineName'])?$_GET["LineName"]:$_POST["LineName"];
		}
		$workorder->data($data)->end();
		//p($data);die;

		break;
	case 'initWorkOrderByPhone':
	//初始化工单（前台）手机端
		$token=gettoken();
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$userType=$user['Type'];
		$uid=$user['uid'];
		$data=$workorder->initWorkOrderByphone($userType);
		// if($userType=="客户"){
		// 	$data['cname']=$user['uname'];
		// 	$data['LineId']=empty($_POST['LineId'])?$_GET["LineId"]:$_POST["LineId"];
		// 	$data['LineName']=empty($_POST['LineName'])?$_GET["LineName"]:$_POST["LineName"];
		// }
		$workorder->data($data)->end();
		//p($data);die;

		break;	
	case 'lineList':
	//客户查看自己已经申请的线路列表（前台）
		$token=$_COOKIE["CCUSER"];
		$current_page=getdata('current_page')==""?"1":getdata('current_page');
		$item_everypage=getdata('item_everypage')==""?"10":getdata('item_everypage');
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$uname=$user['uname'];
		$uid=$user['uid'];
		$region_id=$user['region_id'];
		$role_id=$user['role_id'];
		if($role_id==2)//如果是客户
		{
		   $data=$workorder->getLineListByUname($uname,$current_page,$item_everypage);		
		}
		else
		{
			$data=$workorder->getLineListByManngerId($uid,$region_id,$current_page,$item_everypage);
		}
		$workorder->data($data)->end();
		break;
	case 'lineDetail':
		$Id=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$data=$workorder->getLineDetail($Id);
		$workorder->data($data)->end();
		break;
	case 'lineListByUname':
		$uname=empty($_POST['uname'])?$_GET["uname"]:$_POST["uname"];


		$current_page=getdata('current_page')==""?"1":getdata('current_page');
		$item_everypage=getdata('item_everypage')==""?"10":getdata('item_everypage');
		
		$data=$workorder->getLineListByUname($uname,$current_page,$item_everypage);	

		$workorder->data($data)->end();
		break;
	case 'lineListPhone':
	//客户查看自己已经申请的线路列表（安卓）
		$token=empty($_POST['token'])?$_GET["token"]:$_POST["token"];
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$uname=$user['uname'];
		
		$data=$workorder->getLineListByUname($uname);
		$workorder->data($data)->end();
		break;	
		
	case 'orderListByLineId':
	//查看某个线路的工单列表
		$lineId=empty($_POST['lineId'])?$_GET["lineId"]:$_POST["lineId"];
		//获取分页参数
		$current_page=getdata('current_page')==""?"1":getdata('current_page');
		$item_everypage=getdata('item_everypage')==""?"10":getdata('item_everypage');
		$data=$workorder->workOrderListByLineId($lineId,$current_page,$item_everypage);
		$workorder->data($data)->end();
		break;
	case 'orderListByLineId_Temp':
	//查看某个线路的工单列表
		$lineId=empty($_POST['lineId'])?$_GET["lineId"]:$_POST["lineId"];
		//获取分页参数
		
		$data=$workorder->workOrderListByLineId_temp($lineId);
		$workorder->data($data)->end();
		break;	
	case 'lineRanking':
	//客户查看线路排名（根据每条线路的工单数排名）(前台调用)
		$token=gettoken();
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$uid=$user['uid'];
		$data=$workorder->getLineRank($uid);
		$workorder->data($data)->end();
		break;
	case 'lineRankingPhone':
	//客户查看线路排名（根据每条线路的工单数排名）
		$token=empty($_POST['token'])?$_GET["token"]:$_POST["token"];
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$uid=$user['uid'];
		$data=$workorder->getLineRank($uid);
		$workorder->data($data)->end();
		break;
	case 'contact':
	//得到联系人列表(安卓)
		$token=empty($_POST['token'])?$_GET["token"]:$_POST["token"];
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$uid=$user['uid'];
		$userType=$user['Type'];
		$userRegionId=$user['region_id'];
		$contract=$workorder->getContact($uid,$userType,$userRegionId);
		$workorder->data($contract)->end();
		break;
	case 'noticeList':
		//得到公告列表
		//$token=$_COOKIE["CCUSER"];
		$token=gettoken();
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$current_page=getdata('current_page')==""?"1":getdata('current_page');
		$item_everypage=getdata('item_everypage')==""?"10":getdata('item_everypage');
		
		$region_id=$user['region_id'];
		$type=$user['Type'];
		$data=$workorder->getNoticeList($type,$region_id,$current_page,$item_everypage);
		$workorder->data($data)->end();
		break;
	case 'noticeListPhone':
		//得到公告列表
		$token=empty($_POST['token'])?$_GET["token"]:$_POST["token"];
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$region_id=$user['region_id'];
		$data=$workorder->getNoticeList($region_id);
		$workorder->data($data)->end();
		break;
	case 'noticeDetail':
		$id=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$data=$workorder->getNoticeDetail($id);
		$workorder->data($data)->end();
		break;
	case 'warningList':
		//$token=$_COOKIE["CCUSER"];
		$token=gettoken();
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		
		$current_page=getdata('current_page')==""?"1":getdata('current_page');
		$item_everypage=getdata('item_everypage')==""?"10":getdata('item_everypage');
		//$current_page=empty($_GET['current_page'])?"1":$_GET["current_page"];
		//$item_everypage=empty($_GET['item_everypage'])?"10":$_GET["item_everypage"];
		
		$data=$workorder->getWarningList($user['uid'],$user['Type'],$user['region_id'],$current_page,$item_everypage);
		$workorder->data($data)->end();
		break;
	case 'warningListPhone':
		$token=empty($_POST['token'])?$_GET["token"]:$_POST["token"];
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$data=$workorder->getWarningList($user['uid'],$user['Type'],$user['region_id']);
		$workorder->data($data)->end();
		break;
	case 'warningDetail':
		$id=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$data=$workorder->getWarningDetail($id);
		$workorder->data($data)->end();
		break;
	case 'clientDetail':
		$id=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$data=$workorder->getClientDetail($id);
		$workorder->data($data)->end();
		break;	
	case 'imageList':
		$type=empty($_POST['type'])?$_GET["type"]:$_POST["type"];
		$data=$workorder->getImageList($type);
		$data[0]['active'] = true; //做为显示第一条数据添加active样式		
		$workorder->data($data)->end();
		break;
	case 'NewComment':
		$id=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$data=$workorder->initComment($id);
		$workorder->data($data)->end();
		break;
	case 'commentSubmit':
		$workOrderId=empty($_POST['workOrderId'])?$_GET["workOrderId"]:$_POST["workOrderId"];
		$score=empty($_POST['score'])?$_GET["score"]:$_POST["score"];
		$description=empty($_POST['description'])?$_GET["description"]:$_POST["description"];
		$data=$workorder->commentSubmit($workOrderId,$score,$description);
		$workorder->data($data)->end();
		break;
	case 'viewComment':
		$id=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$data=$workorder->viewComment($id);
		$workorder->data($data)->end();
		break;
	case 'CreateWarning':
		//创建告警
		$token=$_COOKIE["CCUSER"];
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$arr=array();
		$arr["LineNo"]=empty($_POST['LineNo'])?$_GET["LineNo"]:$_POST["LineNo"];
		$arr["WarningLevel"]=empty($_POST['WarningLevel'])?$_GET["WarningLevel"]:$_POST["WarningLevel"];
		$arr["WarningTime"]=empty($_POST['WarningTime'])?strtotime($_GET["WarningTime"]):strtotime($_POST["WarningTime"]);
		$arr["WarningObject"]=empty($_POST['WarningObject'])?$_GET["WarningObject"]:$_POST["WarningObject"];
		$arr["WarningDetail"]=empty($_POST['WarningDetail'])?$_GET["WarningDetail"]:$_POST["WarningDetail"];
		$CreatePersonId=$user['uid'];
		$workorder->createWarning($arr,$user['uid'])->end();
		break;
	case 'lineWarningRank':
		//线路告警排名
		$token=$_COOKIE["CCUSER"];
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$data=$workorder->getLineWaringRank($user['uid']);
		$workorder->data($data)->end();
		break;
	case 'warningLevelRank':
		//线路告警级别排名
		$token=gettoken();
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$current_page=getdata('current_page')==""?"1":getdata('current_page');
		$item_everypage=getdata('item_everypage')==""?"10":getdata('item_everypage');
		
		$data=$workorder->getWarningLevelRank($user['uid'],$current_page,$item_everypage);
		$workorder->data($data)->end();
		break;
	case 'traffic':
		//线路流量统计
		$token=$_COOKIE["CCUSER"];
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$current_page=getdata('current_page')==""?"1":getdata('current_page');
		$item_everypage=getdata('item_everypage')==""?"10":getdata('item_everypage');
		$Type=$user['Type'];
		$region_id=$user['region_id'];
		$data=$workorder->getTrafficTable($region_id,$Type,$user['uid'],$current_page,$item_everypage);
		$workorder->data($data)->end();
		break;
	case 'networkPerformance':
		$token=gettoken();
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$current_page=getdata('current_page')==""?"1":getdata('current_page');
		$item_everypage=getdata('item_everypage')==""?"10":getdata('item_everypage');
		$Type=$user['Type'];
		$region_id=$user['region_id'];
		$data=$workorder->getNetworkPerformance($region_id,$Type,$user['uid'],$current_page,$item_everypage);
		$workorder->data($data)->end();
		break;
	case 'ipPerformance':
		$token=gettoken();
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$current_page=getdata('current_page')==""?"1":getdata('current_page');
		$item_everypage=getdata('item_everypage')==""?"10":getdata('item_everypage');
		$Type=$user['Type'];
		$region_id=$user['region_id'];
		$data=$workorder->getIpPerformance($region_id,$Type,$user['uid'],$current_page,$item_everypage);
		$workorder->data($data)->end();
		break;

	case 'initLinecreate':
		$data=$workorder->initLinecreate();
		$workorder->data($data)->end();
		break;
	case 'createline':
		$token=$_COOKIE["CCUSER"];
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		
		$CientName=empty($_POST['ClientName'])?$_GET['ClientName']:$_POST['ClientName'];	
		//$arr['Context']=empty($_POST['Context'])?$_GET["Context"]:$_POST["Context"];
		$client=$db->getOne("SELECT * from chu_user where uname='".$CientName."'");
		$mangerId=$user['uid'];//当前创建人作为线路管理人员
		$arr=array();
		$arr['Name']=empty($_POST['Name'])?$_GET['Name']:$_POST['Name'];
		$arr['ApplyerId']=$client['uid'];
		$arr['LineA']=empty($_POST['town'])?$_GET['town']:$_POST['town'];
		$arr['LineA']=empty($arr['LineA'])?:getOutlet($arr['LineA'],$db);
		$arr['ALinkMan']=empty($_POST['ALinkMan'])?$_GET['ALinkMan']:$_POST['ALinkMan'];
		$arr['LineB']=empty($_POST['town2'])?$_GET['town2']:$_POST['town2'];
		$arr['LineB']=empty($arr['LineB'])?:getOutlet($arr['LineB'],$db);
		$arr['BLinkMan']=empty($_POST['BLinkMan'])?$_GET['BLinkMan']:$_POST['BLinkMan'];
		$arr['LineBandWidth']=empty($_POST['LineBandWidth'])?$_GET['LineBandWidth']:$_POST['LineBandWidth'];
		$arr['LineRoute']=empty($_POST['LineRoute'])?$_GET['LineRoute']:$_POST['LineRoute'];
		$arr['Describe']=empty($_POST['Describe'])?$_GET['Describe']:$_POST['Describe'];
		$workorder->createLine($arr,$mangerId)->end();
		break;
	case 'initInfocreate':
		$token=$_COOKIE["CCUSER"];
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$uid=$user['uid'];
		$userType=$user['Type'];
		$data=$workorder->getDifUserinfo($uid,$userType);
		//$data=$workorder->initInfocreate($user['uid']);
		$workorder->data($data)->end();
		break;
	case 'updateInfo':
		$token=$_COOKIE["CCUSER"];
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$arr=array();
		$arr['uname']=empty($_POST['uname'])?$_GET['uname']:$_POST['uname'];
		$arr['email']=empty($_POST['email'])?$_GET['email']:$_POST['email'];
		$arr['unit_add_book']=empty($_POST['unit_add_book'])?$_GET['unit_add_book']:$_POST['unit_add_book'];
		$arr['address']=empty($_POST['address'])?$_GET['address']:$_POST['address'];
		
		$arr['unit']=empty($_POST['unit'])?$_GET['unit']:$_POST['unit'];
		$arr['OrganCode']=empty($_POST['OrganCode'])?$_GET['OrganCode']:$_POST['OrganCode'];
		$arr['tax_regis']=empty($_POST['tax_regis'])?$_GET['tax_regis']:$_POST['tax_regis'];
		$arr['busi_license']=empty($_POST['busi_license'])?$_GET['busi_license']:$_POST['busi_license'];
		$workorder->updateInfo($arr,$token)->end();
		break;
	case 'addresource':
		$token=$_COOKIE["CCUSER"];
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$arr=array();
		$arr['UploaderId']=$user['uid'];
		$arr['ImageName']=empty($_POST['ImageName'])?$_GET['ImageName']:$_POST['ImageName'];
		$arr['ImageType']=empty($_POST['ImageType'])?$_GET['ImageType']:$_POST['ImageType'];
		$arr['uploadfile']=$_FILES['uploadfile'];
		p($_POST['uploadfile']);die;
		$workorder->addresource($arr)->end();
		break;
	case 'topologyManage':
	//对所有的拓扑图进行管理
		$data=$workorder->topologyManage();
		$workorder->data($data)->end();
		break;	
	case 'imageManage':
	//对每类拓扑中的图片进行管理
		$type=empty($_POST['type'])?$_GET['type']:$_POST['type'];
		$data=$workorder->imageManage($type);
		$workorder->data($data)->end();
		break;
	case 'deleteImage':
		$Id=empty($_POST['Id'])?$_GET['Id']:$_POST['Id'];
		$workorder->deleteImage($Id);
		break;
	case 'imageSort':
		$Id=empty($_POST['Id'])?$_GET['Id']:$_POST['Id'];
		$type=empty($_POST['type'])?$_GET['type']:$_POST['type'];
		$workorder->imageSort($Id,$type);
		break;
	case 'handlerList':
	//得到某个地区的处理员
		$token=$_COOKIE["CCUSER"];
		$Id=empty($_POST['Id'])?$_GET['Id']:$_POST['Id'];
		$data=$workorder->getHandlerList($token,$Id);
		$workorder->data($data)->end();
		break;
	case 'workorderDispatch':
		$Id=empty($_POST['Id'])?$_GET['Id']:$_POST['Id'];
		$handlerId=empty($_POST['handler'])?$_GET['handler']:$_POST['handler'];
		$dispatcherId=empty($_POST['dispatcherId'])?$_GET['dispatcherId']:$_POST['dispatcherId'];
		$workorder->workorderDispatch($Id,$handlerId,$dispatcherId);
		break;
	case 'workorderReturn':
		//$token=$_COOKIE["CCUSER"];
		$token=gettoken();
		$Id=empty($_POST['Id'])?$_GET['Id']:$_POST['Id'];
		$workorder->workorderReturn($token,$Id);
		break;
	case 'workorderCancel':
		//在工单未处理时可以取消
		$Id=empty($_POST['Id'])?$_GET['Id']:$_POST['Id'];
		$workorder->workorderCancel($Id);
		break;


	/*添加部门@scott*/
	case 'adddep':
		$plevel=empty($_POST['plevel'])?$_GET["plevel"]:$_POST["plevel"];
		$name=empty($_POST['name'])?$_GET["name"]:$_POST["name"];
		$workorder->addDepartment($plevel,$name);
		break;
	/*部门列表@scott*/
	case 'depList':
		$workorder->getDepartment();
		break;
	/*部门详情@scott*/
	case 'depDetail':
		$level=empty($_POST['level'])?$_GET["level"]:$_POST["level"];
		$workorder->getDepdetail($level);
		break;
	/*删除部门@scott*/
	case 'deldep':
		$depid=empty($_POST['depid'])?$_GET["depid"]:$_POST["depid"];
		$workorder->delDepartment($depid);
		break;
	/*添加通知@scott*/
	case 'addnotice':
		$token=$_COOKIE["CCUSER"];
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$title=empty($_POST['title'])?$_GET["title"]:$_POST["title"];
		$context=empty($_POST['context'])?$_GET["context"]:$_POST["context"];
		$workorder->addnotice($title,$context,$user['region_id']);
		break;
	//@allen3039 告警删除
	case 'warningDelete':
		$Id=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$workorder->deleteWarning($Id)->end();
		break;
	//@aalen3039 公告删除
	case 'noticeviewDelete':	
		$Id=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$workorder->deleteNotice($Id)->end();
		break;
	//@allen3039 流量告警删除
	case 'trafficDelete':
		$Id=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$workorder->deleteTraffic($Id)->end();
		break;
	case 'ipperformanceDelete':
		$Id=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$workorder->deleteIPperformance($Id)->end();
		break;			
	case 'networkperformancedelete':
		$Id=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$workorder->deleteNetworkperformance($Id)->end();
		break;				
	//@allen3039 添加IP性能排名 2015-07-04
	case 'IPpfrmcAdd':
	//Name PacketLossRate Twitch Delay
		$Name=getdata('Name');
		$PacketLossRate=getdata('PacketLossRate');
		$Twitch=getdata('Twitch');
		$Delay=getdata('Delay');
		$workorder->addIPpfrmc($Name,$PacketLossRate,$Twitch,$Delay)->end();
		break;
	case 'ntwrkAdd':
		$Name=getdata('Name');
		$ErrorRate=getdata('ErrorRate');
		$NoSecond=getdata('NoSecond');
		$LuminousPower=getdata('LuminousPower');
		$workorder->addntwrk($Name,$ErrorRate,$NoSecond,$LuminousPower)->end();
		break;
	case 'trfcwrAdd':
		$Name=getdata('Name');
		$MinTraffic=getdata('MinTraffic');
		$MaxTraffic=getdata('MaxTraffic');
		$workorder->addtrfcwr($Name,$MinTraffic,$MaxTraffic)->end();
		break;	
	case 'lineRegion':
		//得到某个地区的全部线路
		$token=$_COOKIE["CCUSER"];
		$user=$db->getOne("SELECT * from chu_user where token='".$token."'");
		$workorder->getLineRegion($user['region_id']);
		break;			
}

?>